package org.six11.ss.client;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.six11.util.adt.MultiState;
import org.six11.util.gui.InfoTextBox;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class NotifyPanel extends JPanel {

  private InfoTextBox roleLabel;
  private InfoTextBox clueLabel;
  private MultiState state;

  public NotifyPanel(MultiState ms) {
    super();
    this.state = ms;
    setLayout(new GridLayout(0, 1));
    setBackground(Color.WHITE);
    Font bigFont = new Font("Dialog", Font.PLAIN, 22);
    roleLabel = new InfoTextBox();
    roleLabel.setFont(bigFont);
    add(roleLabel);
    clueLabel = new InfoTextBox();
    clueLabel.setFont(bigFont);
    add(clueLabel);
    state.addChangeListener(ClientStateNames.K_ROLE, new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent evt) {
        String roleType = evt.getNewValue() + "";
        if (roleType.equals("sketcher")) {
          roleLabel.setText("Your turn to sketch! Don't screw up!");
        } else if (roleType.equals("labeler")) {
          roleLabel.setText("Get ready to guess!");
        } else {
          roleLabel.setText("Hmm, the server tells me your role is: " + roleType
              + ". That is an error.");
        }
        repaint();
      }
    });
    state.addChangeListener(ClientStateNames.K_CLUE, new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent evt) {
        clueLabel.setText("");
        String val = state.getString(ClientStateNames.K_CLUE);
        if (val != null) {
          clueLabel.append(Color.BLACK, "This round's text:\n\n");
          clueLabel.append(Color.RED, state.getString(ClientStateNames.K_CLUE));
        }
      }
    });
  }

}
